package com.base.controller;

import com.base.service.FilmAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 分类广告管理服务端
 *
 * @author f
 */
@Controller
@RequestMapping("/admin")
public class index_FilmAd {

    @Autowired
    private FilmAdService filmAdService; // 广告信息

    // 广告首页
    @RequestMapping("/filmAdIndex")
    public ModelAndView filmAdIndex(HttpServletRequest request) throws Exception {
        String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
        if (userid == null) return new ModelAndView("jsp/loginCheck"); // 未登录
        return new ModelAndView("jsp/index_FilmAd", "filmAdList", filmAdService.selectByAll(userid, null));
    }

    // 跳转添加广告
    @RequestMapping("/addFilmAd")
    public String addFilmAd() throws Exception {
        return "jsp/add_FilmAd";
    }

    // 跳转修改广告
    @RequestMapping("/updateFilmAd")
    public ModelAndView updateFilmAd(String id) throws Exception {
        return new ModelAndView("jsp/update_FilmAd", "filmAd", filmAdService.selectByPrimaryKey(id));
    }
}
